package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.pojo.Phone;
import com.shop.pojo.Result;
import com.shop.service.PhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



import java.util.List;


/**
 * 本来用来演示:
 * 手机的后端(控制层)
 *
 * 代码也是一个资源,每个资源都有唯一的一个url
 * url的格式
 * 协议://Ip地址:端口号/项目上下文路径/资源映射路径
 * localhost:8088/boot/phone/hello
 *
 * @author success
 * @date 2024/6/18 10:46:16
 */
@RestController //=@Controller+@ResponseBody
@RequestMapping("phone")
public class PhoneController {
    @Autowired
    private PhoneService phoneService;

    @GetMapping("index")
    public Result index(@RequestParam(defaultValue = "1") Integer pageNow, @RequestParam(defaultValue = "12") Integer pageSize, String name){
        PageInfo<Phone> pageInfo = phoneService.pages(pageNow,pageSize,name);
        return new Result("200","查询成功",pageInfo);
    }











//    @GetMapping("hello")
//    public Result hello(){
//        //模拟查询操作
//        //创建一个Phone对象
//        Phone phone=new Phone();
//        phone.setId(1);
//        phone.setName("小米");
//        phone.setCreateDate(new Date());
//        phone.setImgUrl("x.png");
//        phone.setStock(100);
//
//        return new Result("200","查询成功",phone);
//    }
}
